home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH12 / 12-1-1.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1998-11-02  |  6.2 KB  |  201 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDBMan 
  3.    Caption         =   "Database Management"
  4.    ClientHeight    =   2925
  5.    ClientLeft      =   1065
  6.    ClientTop       =   1710
  7.    ClientWidth     =   5415
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    ForeColor       =   &H80000008&
  18.    LinkTopic       =   "Form1"
  19.    PaletteMode     =   1  'UseZOrder
  20.    ScaleHeight     =   2925
  21.    ScaleWidth      =   5415
  22.    Begin VB.TextBox txtCountry 
  23.       DataField       =   "country"
  24.       DataSource      =   "datCities"
  25.       Height          =   285
  26.       Left            =   2040
  27.       TabIndex        =   6
  28.       Top             =   1560
  29.       Width           =   2895
  30.    End
  31.    Begin VB.TextBox txtPop2015 
  32.       DataField       =   "pop2015"
  33.       DataSource      =   "datCities"
  34.       Height          =   285
  35.       Left            =   2040
  36.       TabIndex        =   8
  37.       Top             =   2520
  38.       Width           =   2895
  39.    End
  40.    Begin VB.TextBox txtPop1995 
  41.       DataField       =   "pop1995"
  42.       DataSource      =   "datCities"
  43.       Height          =   285
  44.       Left            =   2040
  45.       TabIndex        =   7
  46.       Top             =   2040
  47.       Width           =   2895
  48.    End
  49.    Begin VB.TextBox txtCity 
  50.       DataField       =   "city"
  51.       DataSource      =   "datCities"
  52.       Height          =   285
  53.       Left            =   2040
  54.       TabIndex        =   5
  55.       Top             =   1080
  56.       Width           =   2895
  57.    End
  58.    Begin VB.Data datCities 
  59.       Caption         =   "Large World Cities"
  60.       Connect         =   "Access"
  61.       DatabaseName    =   "MEGACTY1.MDB"
  62.       DefaultCursorType=   0  'DefaultCursor
  63.       DefaultType     =   2  'UseODBC
  64.       Exclusive       =   0   'False
  65.       Height          =   300
  66.       Left            =   480
  67.       Options         =   0
  68.       ReadOnly        =   0   'False
  69.       RecordsetType   =   1  'Dynaset
  70.       RecordSource    =   "Cities"
  71.       Top             =   600
  72.       Width           =   4455
  73.    End
  74.    Begin VB.CommandButton cmdQuit 
  75.       Caption         =   "Quit"
  76.       Height          =   375
  77.       Left            =   4080
  78.       TabIndex        =   3
  79.       Top             =   120
  80.       Width           =   1215
  81.    End
  82.    Begin VB.CommandButton cmdSearch 
  83.       Caption         =   "Search"
  84.       Height          =   375
  85.       Left            =   2760
  86.       TabIndex        =   2
  87.       Top             =   120
  88.       Width           =   1215
  89.    End
  90.    Begin VB.CommandButton cmdDelete 
  91.       Caption         =   "Delete"
  92.       Height          =   375
  93.       Left            =   1440
  94.       TabIndex        =   1
  95.       Top             =   120
  96.       Width           =   1215
  97.    End
  98.    Begin VB.CommandButton cmdAdd 
  99.       Caption         =   "Add"
  100.       Height          =   375
  101.       Left            =   120
  102.       TabIndex        =   0
  103.       Top             =   120
  104.       Width           =   1215
  105.    End
  106.    Begin VB.Label lblCountry 
  107.       Caption         =   "Country:"
  108.       Height          =   255
  109.       Left            =   1200
  110.       TabIndex        =   11
  111.       Top             =   1560
  112.       Width           =   735
  113.    End
  114.    Begin VB.Label lblPop2015 
  115.       Alignment       =   1  'Right Justify
  116.       Caption         =   "2015 Population:"
  117.       Height          =   255
  118.       Left            =   480
  119.       TabIndex        =   10
  120.       Top             =   2520
  121.       Width           =   1455
  122.    End
  123.    Begin VB.Label lblPop1995 
  124.       Alignment       =   1  'Right Justify
  125.       Caption         =   "1995 Population:"
  126.       Height          =   255
  127.       Left            =   480
  128.       TabIndex        =   9
  129.       Top             =   2040
  130.       Width           =   1455
  131.    End
  132.    Begin VB.Label lblCity 
  133.       Alignment       =   1  'Right Justify
  134.       Caption         =   "City:"
  135.       Height          =   255
  136.       Left            =   1560
  137.       TabIndex        =   4
  138.       Top             =   1080
  139.       Width           =   375
  140.    End
  141. Attribute VB_Name = "frmDBMan"
  142. Attribute VB_GlobalNameSpace = False
  143. Attribute VB_Creatable = False
  144. Attribute VB_PredeclaredId = True
  145. Attribute VB_Exposed = False
  146. Private Sub cmdAdd_Click()
  147.   'Add a new record
  148.   datCities.Recordset.AddNew
  149.   txtCity.SetFocus 'Data must be entered and a new record moved to
  150. End Sub
  151. Private Sub cmdDelete_Click()
  152.   'Delete the currently displayed record
  153.   datCities.Recordset.Delete
  154.   'Move so that user sees deleted record disappear
  155.   datCities.Recordset.MoveNext
  156.   If datCities.Recordset.EOF Then
  157.       datCities.Recordset.MovePrevious
  158.   End If
  159. End Sub
  160. Private Sub cmdQuit_Click()
  161.   End
  162. End Sub
  163. Private Sub cmdSearch_Click()
  164.   Dim strSearchFor As String, foundFlag As Boolean
  165.   'Search for the city specified by the user
  166.   strSearchFor = UCase(InputBox("Name of city to find:"))
  167.   If Len(strSearchFor) > 0 Then
  168.       datCities.Recordset.MoveFirst
  169.       foundFlag = False
  170.       Do While (Not foundFlag) And (Not datCities.Recordset.EOF)
  171.         If UCase(datCities.Recordset.Fields("City").Value) = strSearchFor Then
  172.             foundFlag = True
  173.           Else
  174.             datCities.Recordset.MoveNext
  175.         End If
  176.       Loop
  177.       If Not foundFlag Then
  178.           MsgBox "Unable to locate requested city.", , "Not Found"
  179.           datCities.Recordset.MoveLast  'move so that EOF is no longer true
  180.       End If
  181.     Else
  182.       MsgBox "Must enter a city.", , ""
  183.   End If
  184. End Sub
  185. Private Sub datCities_Validate(Action As Integer, Save As Integer)
  186.   'Prevent a user from adding a city of population under 1 millio
  187.   Dim strMsg As String
  188.   If Val(txtPop1995) < 1 Then
  189.     If Not datCities.Recordset.EOF And Not datCities.Recordset.BOF Then
  190.       strMsg = "We only allow cities having a population of " & _
  191.                "at least one million."
  192.       MsgBox strMsg, , "City too small!"
  193.       Action = 0
  194.     End If
  195.   End If
  196. End Sub
  197. Private Sub Form_Load()
  198.   'Look for the data base in the same folder as the program
  199.   datCities.DatabaseName = App.Path & "\MEGACTY1.MDB"
  200. End Sub
  201.